
import { _decorator } from 'cc';
import { CursorView } from './CursorView';

import { SuperButton } from '../keyboard/base/SuperButton';


export class CursorController {
    private static ins: CursorController
    static instance() {
        if (!this.ins) {
            this.ins = new CursorController();
        }
        return this.ins;
    }

    private _cursorView: CursorView = null;
    public set cursorView(value: CursorView) {
        this._cursorView = value;
    }

    public get cursorView(): CursorView {
        return this._cursorView;
    }


    public init() {
    }

    /**
     * 隐藏光标
     */
    public hideCursor() {
        this.cursorView.node.active = false;
    }

    /**
     * 显示光标
     */
    public showCursor() {
        this.cursorView.node.active = true;
    }

    public onFocusEvent(itemView: SuperButton) {
        if (this._cursorView) {
            this.showCursor();
            this._cursorView.onFocusEvent(itemView);
        }
    }

    public onBlurEvent(itemView: SuperButton) {
        if (this._cursorView) {
            this._cursorView.onBlurEvent(itemView);
        }
    }

    /**
     * 清除光标
     */
    public clearCursorView() {
        this.onBlurEvent(this._cursorView?.getFocusedSuperButton());
    }
}